const express = require("express");
const cors = require("cors");
const jwt = require("express-jwt");
const joi = require("joi");
const app = express();

app.use(cors());
app.use(express.json({limit: '50mb'})); // 添加这个中间件以解析JSON格式的请求体
app.use(express.urlencoded({ extended: false }));

app.use((err, req, res, next) => {
  res.status(500).send("Something broke!");
});

// 配置JWT
const config = require("./config");
app.use(jwt({ secret: config.jwtSecretKey }).unless({ path: [/^\/api\//] }));

const userRouter = require("./routers/user");
app.use("/api", userRouter);

const userinfoRouter = require("./routers/userinfo");
app.use("/my", userinfoRouter);

const creditRouter = require("./routers/credit.js");
app.use("/api/credit", creditRouter);

// 创建一个新的路由来处理微信登录
const wechatAuthRouter = require("./routers/wechatAuthRouter.js");
app.use("/api", wechatAuthRouter);

const videorouter = require("./myvideo/video_router.js");
app.use("/api/video", videorouter);

const human_count_router = require("./routers/humancount_router.js")
app.use("/api/human_count", human_count_router);

app.listen(8080, () => {
  console.log("API server running at http://127.0.0.1:8080");
});
